#coding:utf-8

import mood_sys
import json
import random

def feedback(host_name, mood, inti_info):
    '''
    此代码用于结合心情系数和亲密度选择反馈
    :param mood:代表心情系数
    :param inti_socre:代表亲密度字典
    :return:feedback_action 代表反馈动作
    反馈动作包括：
    小熊：开心：摇尾巴、不断眨眼睛、围着主人转圈圈、欢蹦乱跳、跳起来要主人抱抱、后腿站立用前爪趴着主人、蹭主人
         难过：趴着、爱理不理、吠叫、和主人保持距离、站立不动
    人：开心：笑、
    难过：低头、不愿意说话、

    结合两者，心情系数和亲密度各占50%
    '''
    mood_best_action = ['欢蹦乱跳', '前腿跳起要主人抱抱', '围着主人转圈圈', '用头蹭主人']
    mood_alm_action = ['摇尾巴' , '不断眨眼睛（跟着主人的目光走）']
    mood_bad_action = ['趴着', '不看主人', '吠叫', '不理会', '站立不动', '与主人保持距离']
    feedback_best_silent_action = ['前腿跳起要主人抱抱', '用头蹭主人' ]
    feedback_best_positive_action = ['欢蹦乱跳', '围着主人转圈圈']
    feedback_alm_silent_action = ['不断眨眼睛（跟着主人的目光走）']
    feedback_alm_positive_action = ['摇尾巴']
    feedback_bad_silent_action = ['趴着', '不理会', '站立不动' ]
    feedback_bad_positive_action = [ '吠叫', '与主人保持距离']

    if host_name not in inti_score.keys():
        feedback_num = mood
        if feedback_num > 85 : action = random.choice(mood_best_action)
        elif feedback_num > 60 : action = random.choice(mood_alm_action)
        else : action = random.choice(mood_bad_action)
    else:
        info = inti_score[host_name]
        inti_num = info['times_score']
        inti_num_add = float(info['day_score'])
        feedback_num = 0.5 * mood + 0.5 * inti_num #多元计算的亲密度结合心情系数
        feedback_num_add = 0.5 * mood + 0.5 * inti_num_add #递增计算的亲密度结合心情系数
        #print(inti_num, inti_num_add)

        ####针对多元计算结果做反馈
        #print(inti_info['torch_all_times'], type(inti_info['torch_all_times']))
        ##############改
        if feedback_num > 85 :
            if mood > 85:
                if inti_info['torch_all_times'] > 10 : action = random.choice(feedback_best_positive_action)
                else : action = random.choice(feedback_best_silent_action)
            else :
                if inti_info['torch_all_times'] > 10 : action = random.choice(feedback_best_silent_action)
                else : action = random.choice(feedback_best_positive_action)
        elif feedback_num > 60 :
            if mood > 85:
                if inti_info['torch_all_times'] > 10 : action = random.choice(feedback_alm_positive_action)
                else : action = random.choice(feedback_alm_silent_action)
            else :
                if inti_info['torch_all_times'] > 10 : action = random.choice(feedback_alm_silent_action)
                else : action = random.choice(feedback_alm_positive_action)
        else :
            if mood > 85:
                if inti_info['torch_all_times'] > 10 : action = random.choice(feedback_bad_positive_action)
                else : action = random.choice(feedback_bad_silent_action)
            else :
                if inti_info['torch_all_times'] > 10 : action = random.choice(feedback_bad_silent_action)
                else : action = random.choice(feedback_bad_positive_action)
    print(host_name, feedback_num, feedback_num_add, action)



if __name__ == '__main__':
    #获取当前主人姓名
    #host_name = 'ling' #这个需要自己去获取
    #获取心情系数
    mood = mood_sys.mood_sys()
    mood_num = mood.get_mood_count()

    # 获取每个人的亲密度
    f = open("inti_score.json", encoding='utf-8')
    inti_score = json.load(f)

    # 把信息都导入到反馈系统中
    #print(list(inti_score.keys()))
    for host_name in list(inti_score.keys()):
        feedback(host_name, mood_num, inti_score[host_name])


    #feedback(host_name, mood_num, inti_score)